﻿Imports DTO
Imports BUS

Public Class frmTraCuuHocSinh

    Private Sub LoadLopHoc()
        Dim lhBus As New LopHocBus()
        Dim danhSachLop As List(Of LopHocDto)
        danhSachLop = lhBus.LayDSLop()
        cbbLopHoc.DataSource = danhSachLop
        cbbLopHoc.ValueMember = "MaLop"
        cbbLopHoc.DisplayMember = "TenLop"
    End Sub

    Private Sub frmTraCuuHocSinh_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LoadLopHoc()
    End Sub

    Private Sub LayDanhSachHocSinh()
        Dim dt As DataTable = HocSinhBus.LayDanhSachHocSinh()
        For i As Integer = 0 To dt.Rows.Count - 1
            gridViewDSHocSinh.Rows.Add()
            gridViewDSHocSinh.Item("clSTT", i).Value = (i + 1).ToString()
            gridViewDSHocSinh.Item("clHoTen", i).Value = dt.Rows.Item(i)("TenHS")
            gridViewDSHocSinh.Item("clLop", i).Value = dt.Rows.Item(i)("TenLop")
        Next
    End Sub

    Private Sub btnLayDanhSach_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLayDanhSach.Click
        LayDanhSachHocSinh()
    End Sub

    Private Sub LayDanhSachHocSinhTheoLop()
        Dim lh As LopHocDto = cbbLopHoc.SelectedItem
        Dim maLop As Integer = lh.MaLop
        Dim dt As DataTable = LopHocBus.LayDanhSachHocSinhTheoLop(maLop)
        For i As Integer = 0 To dt.Rows.Count - 1
            gridViewDSHocSinh.Rows.Add()
            gridViewDSHocSinh.Item("clSTT", i).Value = (i + 1).ToString()
            gridViewDSHocSinh.Item("clHoTen", i).Value = dt.Rows.Item(i)("TenHS")
            gridViewDSHocSinh.Item("clLop", i).Value = lh.TenLop
        Next
    End Sub

    Private Sub cbbLopHoc_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cbbLopHoc.SelectedIndexChanged
        gridViewDSHocSinh.Rows.Clear()
        LayDanhSachHocSinhTheoLop()
    End Sub
End Class